package com.payment.controller;



import com.payment.entity.Make;
import com.payment.entity.MakeWithDoctorDto;
import com.payment.service.MakeService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/make")  //预约挂号的接口
public class MakeController {

    @Resource
    private MakeService makeService;

    @GetMapping("/getAll") //查询预约表
    public ResponseEntity<ResDTO>getAll(){
        List<MakeWithDoctorDto> _list =  makeService.getAll();
        return ResponseEntity.ok(ResDTO.success(_list));
    }

    @GetMapping("/getByMakeState/{state}") //根据状态查询
    public ResponseEntity<ResDTO> getByMakeState(@PathVariable int state){
        List<MakeWithDoctorDto> _list =  makeService.getByMakeState(state);
        if (_list!=null){
            return ResponseEntity.ok(ResDTO.success(_list));
        }else {
            return ResponseEntity.ok(ResDTO.error());
        }
    }

    @PostMapping("/addMake")
    public ResponseEntity<ResDTO> addMake(@RequestBody Make entity){
        System.out.println(entity.getDoctorId());

        int res = makeService.add(entity);

        if (res>0){
            return ResponseEntity.ok(ResDTO.success(null));
        }else {
            return ResponseEntity.ok(ResDTO.error());
        }
    }

    @DeleteMapping("/delMake/{id}") //根据预约表id取消挂号
    public ResponseEntity<ResDTO> delMake(@PathVariable int id){

        int res = makeService.del(id);

        if (res>0){
            return ResponseEntity.ok(ResDTO.success(null));
        }else {
            return ResponseEntity.ok(ResDTO.error());
        }
    }
}
